package com.leyou.user.service.mapper;

import com.leyou.common.bean.IBaseMapper;
import com.leyou.user.inter.pojo.Permission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper extends IBaseMapper<Permission> {

    @Select("select p.id,p.url,p.method from tb_permission p left join tb_role_permission r on p.id=r.permission_id where r.role_id=#{rid} and p.is_enable=1")
    List<Permission> selectPermissionByCid(@Param("rid") Long rid);

    @Select("select p.id,p.url,p.method from tb_permission p left join tb_role_permission r on p.id=r.permission_id where r.role_id=#{rid} and p.parent_id=#{parentId} and p.is_enable=1")
    List<Permission> selectPermissionBySelect(@Param("rid") Long rid,@Param("parentId") Long parentId);

    @Select("select id,url,icon,name,method from tb_permission where id in(select permission_id from tb_role_permission where role_id in(${rids}) GROUP BY permission_id) and parent_id=#{parentId} and type=#{type} and is_enable=1 ORDER BY sort")
    List<Permission> selectMenuByUser(@Param("rids") String rids,@Param("parentId") Long parentId,@Param("type") Integer type);

}